package com.scw.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.scw.model.Advertsing;
import com.scw.service.AdvertsingService;

/**
 * 广告管理类
 * @author 王华聪
 *
 */
public class AdvertsingAction {
	private Advertsing advertsing;
	private AdvertsingService advertsingService;
	/**
	 * 添加广告
	 * @return
	 */
	public String add(){
		advertsingService.add(advertsing);
		return "add";
	}
	/**
	 * 更新广告
	 * @return
	 */
	public String update(){
		advertsingService.update(advertsing);
		return "update";
	}
	/**
	 * 删除广告
	 * @return
	 */
	public String del(){
		HttpServletRequest req=ServletActionContext.getRequest();
		String[] ids=(String[]) req.getAttribute("checkboxs");
		advertsing=new Advertsing();
		for(String id:ids){
			advertsing.setId(Long.valueOf(id));
			advertsingService.del(advertsing);
		}
		return "del";
	}
	/**
	 * 获取广告
	 * @return
	 */
	public String get(){
		HttpServletRequest req=ServletActionContext.getRequest();
		Long id=Long.valueOf(req.getParameter("id"));
		advertsing=advertsingService.get(id);
		req.setAttribute("advertsing", advertsing);
		return "get";
	}
	/**
	 * 显示广告list
	 * @return
	 */
	public String all(){
		HttpServletRequest req=ServletActionContext.getRequest();
		String location=req.getParameter("location");
		advertsing=new Advertsing();
		advertsing.setLocation(location);
		List<Advertsing> list=new ArrayList<Advertsing>();
		list=advertsingService.getall(advertsing);
		req.setAttribute("list", list);
		return "all";
	}
	public Advertsing getAdvertsing() {
		return advertsing;
	}
	public void setAdvertsing(Advertsing advertsing) {
		this.advertsing = advertsing;
	}
	public AdvertsingService getAdvertsingService() {
		return advertsingService;
	}
	public void setAdvertsingService(AdvertsingService advertsingService) {
		this.advertsingService = advertsingService;
	}
	
}
